from osgeo import ogr
import os
import sys

ogr.UseExceptions()

driver:ogr.Driver = ogr.GetDriverByName("GeoJSON")

path = os.path.join(os.getcwd(), "Include", "dataset", "01.geojson")
try:
    f = open(path)
    f.close()
except FileExistsError:
  sys.exit()

dataset:ogr.DataSource = driver.Open(path)

layer:ogr.Layer = dataset.GetLayer(0)

out_file =  os.path.join(os.getcwd(), "Include", "dataset", "point.csv")

for index, feature in  enumerate(layer):
    feature: ogr.Feature
    geometry: ogr.Geometry = feature.GetGeometryRef()
    with open(out_file,"a") as f:
        f.write("%d,%.8f,%.8f,POINT,A%d\n"%(index,geometry.GetX(),geometry.GetY(),index))
    f.close()